<?php

Raise::load('core.js.RaiseJavascript');

/**
 * TestCoreRaiseJavascript class
 * Testing unit of 'phpraise/core/RaiseJavascript.php'
 *
 * @author Sam-Mauris Yong / hellclanner at live dot com
 * @license http://www.opensource.org/licenses/bsd-license New BSD License
 * @package Raise.UnitTest.Test
 */
class TestCoreRaiseJavascript extends RaiseTest {

    public static function testClass(){
        self::assertClassExists('RaiseJavascript');
        self::assertClassExtends('RaiseJavascript', 'RaiseStaticClass');

        self::assertClassMethod('RaiseJavascript', 'block');
        self::assertType(RaiseJavascript::block('runSomeJSFunc();'), 'object');
        self::assertObjectClass(RaiseJavascript::block('runSomeJSFunc();'), 'RaiseHtmlTag');
        self::assertType(RaiseJavascript::block('runSomeJSFunc();', true), 'object');
        self::assertObjectClass(RaiseJavascript::block('runSomeJSFunc();', true), 'RaiseHtmlTag');

        self::assertClassMethod('RaiseJavascript', 'file');
        self::assertType(RaiseJavascript::file('script/somejsfile.js'), 'object');
        self::assertObjectClass(RaiseJavascript::file('script/somejsfile.js'), 'RaiseHtmlTag');
        self::assertType(RaiseJavascript::file('script/somejsfile.js', true), 'object');
        self::assertObjectClass(RaiseJavascript::file('script/somejsfile.js', true), 'RaiseHtmlTag');
        self::assertStrictEqual(RaiseJavascript::file('script/somejsfile.js')->attributes()->get('src'), 'script/somejsfile.js');
        self::assertStrictEqual(RaiseJavascript::file('script/somejsfile.js',true)->attributes()->get('src'), 'script/somejsfile.js');

        self::assertClassMethod('RaiseJavascript', 'helper');

        self::assertType(RaiseJavascript::helper(), 'object');
        self::assertObjectClass(RaiseJavascript::helper(), 'RaiseHtmlTag');
        self::assertStrictEqual(RaiseJavascript::helper()->attributes()->get('type'), 'text/javascript');
        self::assertStrictEqual(RaiseJavascript::helper()->attributes()->get('src'), RaiseUrl::combine('', 'raise.js'));

        self::assertType(RaiseJavascript::helper('http://localhost/someroot'), 'object');
        self::assertObjectClass(RaiseJavascript::helper('http://localhost/someroot'), 'RaiseHtmlTag');
        self::assertStrictEqual(RaiseJavascript::helper('http://localhost/someroot')->attributes()->get('type'), 'text/javascript');
        self::assertStrictEqual(RaiseJavascript::helper('http://localhost/someroot')->attributes()->get('src')->__toString(), RaiseUrl::combine('http://localhost/someroot', 'raise.js')->__toString());

        self::assertClassMethod('RaiseJavascript', 'includeJquery');
        self::assertType(RaiseJavascript::includeJquery(), 'object');
        self::assertObjectClass(RaiseJavascript::includeJquery(), 'RaiseHtmlTag');
        self::assertType(RaiseJavascript::includeJquery()->attributes()->get('src'), 'string');
        self::assertType(RaiseJavascript::includeJquery('1.2'), 'object');
        self::assertObjectClass(RaiseJavascript::includeJquery('1,2'), 'RaiseHtmlTag');
        self::assertType(RaiseJavascript::includeJquery('1.2')->attributes()->get('src'), 'string');

        self::assertClassMethod('RaiseJavascript', 'jqueryOnload');
        self::assertType(RaiseJavascript::jqueryOnload('window.title = "awesome";'), 'string');
        
        self::assertClassMethod('RaiseJavascript', 'jqueryLoad');
        self::assertType(RaiseJavascript::jqueryLoad('#test', 'http://www.example.com/'), 'string');
        self::assertType(RaiseJavascript::jqueryLoad('#test', 'http://www.example.com/', new RaiseCollection()), 'string');
        self::assertType(RaiseJavascript::jqueryLoad('#test', 'http://www.example.com/', new RaiseCollection(), 'function(){callback();}'), 'string');

        self::assertClassMethod('RaiseJavascript', 'jqueryEventBind');
        
        self::assertClassMethod('RaiseJavascript', 'includeJqueryUi');
        self::assertType(RaiseJavascript::includeJqueryUi(), 'object');
        self::assertObjectClass(RaiseJavascript::includeJqueryUi(), 'RaiseHtmlTag');
        self::assertType(RaiseJavascript::includeJqueryUi()->attributes()->get('src'), 'string');
        self::assertType(RaiseJavascript::includeJqueryUi('1.2'), 'object');
        self::assertObjectClass(RaiseJavascript::includeJqueryUi('1,2'), 'RaiseHtmlTag');
        self::assertType(RaiseJavascript::includeJqueryUi('1.2')->attributes()->get('src'), 'string');
        
        self::assertClassMethod('RaiseJavascript', 'includeMooTools');
        self::assertType(RaiseJavascript::includeMooTools(), 'object');
        self::assertObjectClass(RaiseJavascript::includeMooTools(), 'RaiseHtmlTag');
        self::assertType(RaiseJavascript::includeMooTools()->attributes()->get('src'), 'string');
        self::assertType(RaiseJavascript::includeMooTools('1.2'), 'object');
        self::assertObjectClass(RaiseJavascript::includeMooTools('1,2'), 'RaiseHtmlTag');
        self::assertType(RaiseJavascript::includeMooTools('1.2')->attributes()->get('src'), 'string');

        self::assertClassMethod('RaiseJavascript', 'includePrototype');
        self::assertType(RaiseJavascript::includePrototype(), 'object');
        self::assertObjectClass(RaiseJavascript::includePrototype(), 'RaiseHtmlTag');
        self::assertType(RaiseJavascript::includePrototype()->attributes()->get('src'), 'string');
        self::assertType(RaiseJavascript::includePrototype('1.2'), 'object');
        self::assertObjectClass(RaiseJavascript::includePrototype('1,2'), 'RaiseHtmlTag');
        self::assertType(RaiseJavascript::includePrototype('1.2')->attributes()->get('src'), 'string');

        self::assertClassMethod('RaiseJavascript', 'includeYui');
        self::assertType(RaiseJavascript::includeJquery(), 'object');
        self::assertObjectClass(RaiseJavascript::includeJquery(), 'RaiseHtmlTag');
        self::assertType(RaiseJavascript::includeJquery()->attributes()->get('src'), 'string');
        self::assertType(RaiseJavascript::includeJquery('1.2'), 'object');
        self::assertObjectClass(RaiseJavascript::includeJquery('1,2'), 'RaiseHtmlTag');
        self::assertType(RaiseJavascript::includeJquery('1.2')->attributes()->get('src'), 'string');

        self::assertClassMethod('RaiseJavascript', 'includeDojo');
        self::assertType(RaiseJavascript::includeDojo(), 'object');
        self::assertObjectClass(RaiseJavascript::includeDojo(), 'RaiseHtmlTag');
        self::assertType(RaiseJavascript::includeDojo()->attributes()->get('src'), 'string');
        self::assertType(RaiseJavascript::includeDojo('1.2'), 'object');
        self::assertObjectClass(RaiseJavascript::includeDojo('1,2'), 'RaiseHtmlTag');
        self::assertType(RaiseJavascript::includeDojo('1.2')->attributes()->get('src'), 'string');

        self::assertClassMethod('RaiseJavascript', 'promptBeforeUnload');
        self::assertType(RaiseJavascript::promptBeforeUnload('You better not leave the page.'), 'string');
    }

}
